package com.example.springboot01.utils;

import java.util.regex.Pattern;

/**
 * 注册参数校验
 * @author developer
 * @since 2022-5-10
 */
public class ParamsMatchUtils {

    //电信
    public final static String telecomTelReg = "^(?:133|149|153|162|1700|1701|1702|173|177|18[019]|19[0139])\\d{7,8}$";

    //移动
    public final static String mobileTelReg = "^134[0-8]\\d{7}$|^(?:13[5-9]|147|15[0-27-9]|178|1703|1705|1706|18[2-478])\\d{7,8}$";

    //联通
    public final static String unicomTelReg = "^(?:13[0-2]|145|15[56]|176|167|1704|1707|1708|1709|171|18[56])\\d{7,8}$";

    //密码
    public final static String passwordReg = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$";

    //用户名
    public final static String UserNameReg = "^[a-zA-Z0-9_-]{4,16}$";

    //邮箱
    public final static String emailReg = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";

    //匹配电话
    public static boolean telephoneMatch(String telephone) {
        //匹配电话号码
        if (telephone == null) {
            return false;
        }
        if (Pattern.matches(telecomTelReg, telephone) || Pattern.matches(mobileTelReg, telephone) || Pattern.matches(unicomTelReg, telephone)) {
            //匹配
            return true;
        }
        return false;
    }

    //匹配密码
    //只能包含字母和数字，须6-16位
    public static boolean passwordMatch(String password) {
        if (password == null) {
            return false;
        }
        if (!Pattern.matches(passwordReg, password)) {
            return false;
        }
        return true;
    }

    //匹配用户名
    //4到16位（字母，数字，下划线，减号）
    public static boolean userNameMatch(String userName) {
        if (userName == null) {
            return false;
        }
        if (!Pattern.matches(UserNameReg, userName)) {
            return false;
        }
        return true;
    }

    //匹配邮箱
    public static boolean emailmatch(String email) {
        if (email == null) {
            return false;
        }
        if (!Pattern.matches(emailReg, email)) {
            return false;
        }
        return true;
    }
}
